//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ParkinsonSigma.h"
using namespace Cephei::QL::Models::Volatility;
#include <gen/QL/Models/Volatility/GarmanKlassAbstract.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (Double y) : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
    try
    {
#ifdef HANDLE
        _phParkinsonSigma = NULL;
#endif
        QuantLib::Real _y = (QuantLib::Real)ValueHelper::Convert (y);
        _ppParkinsonSigma = new boost::shared_ptr<QuantLib::ParkinsonSigma> (new QuantLib::ParkinsonSigma ( _y ));
        SetGarmanKlassAbstract (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (boost::shared_ptr<QuantLib::ParkinsonSigma>& childNative, Object^ owner) : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
#ifdef HANDLE
	_phParkinsonSigma = NULL;
#endif
	_ppParkinsonSigma = &childNative;
    _ppGarmanKlassAbstract = new boost::shared_ptr<QuantLib::GarmanKlassAbstract> (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
}
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (QuantLib::ParkinsonSigma& childNative, Object^ owner) : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
#ifdef HANDLE
	_phParkinsonSigma = NULL;
#endif
	_ppParkinsonSigma = new boost::shared_ptr<QuantLib::ParkinsonSigma> (&childNative);
    _ppGarmanKlassAbstract = new boost::shared_ptr<QuantLib::GarmanKlassAbstract> (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
    _ParkinsonSigmaOwner = owner;
    _GarmanKlassAbstractOwner = owner;
}

Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (CParkinsonSigma^ copy) : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
#ifdef HANDLE
	_phParkinsonSigma = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppParkinsonSigma = new boost::shared_ptr<QuantLib::ParkinsonSigma> (copy->GetShared());
        _ppGarmanKlassAbstract = new boost::shared_ptr<QuantLib::GarmanKlassAbstract> (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
    }
}
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (System::Type^ t) : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
#ifdef HANDLE
	_phParkinsonSigma = NULL;
#endif
	if (!t->IsSubclassOf(CParkinsonSigma::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (QuantLib::Handle<QuantLib::ParkinsonSigma>& childNative, Object^ owner)  : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
	_phParkinsonSigma = &childNative;
	_ppParkinsonSigma = &static_cast<boost::shared_ptr<QuantLib::ParkinsonSigma>>(childNative.currentLink());
    _ppGarmanKlassAbstract = new boost::shared_ptr<QuantLib::GarmanKlassAbstract> (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
    _ParkinsonSigmaOwner = owner;
}
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (QuantLib::Handle<QuantLib::ParkinsonSigma> childNative)  : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
	_phParkinsonSigma = &childNative;
	_ppParkinsonSigma = &static_cast<boost::shared_ptr<QuantLib::ParkinsonSigma>>(childNative.currentLink());
    _ppGarmanKlassAbstract = new boost::shared_ptr<QuantLib::GarmanKlassAbstract> (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Volatility::CParkinsonSigma::CParkinsonSigma (QuantLib::ParkinsonSigma childNative)  : CGarmanKlassAbstract(CParkinsonSigma::typeid)
{
#ifdef HANDLE
	_phParkinsonSigma = NULL;
#endif
	_ppParkinsonSigma = new boost::shared_ptr<QuantLib::ParkinsonSigma> (new QuantLib::ParkinsonSigma (childNative));
    _ppGarmanKlassAbstract = new boost::shared_ptr<QuantLib::GarmanKlassAbstract> (boost::dynamic_pointer_cast<QuantLib::GarmanKlassAbstract> (*_ppParkinsonSigma));
}
#endif

Cephei::QL::Models::Volatility::CParkinsonSigma::~CParkinsonSigma ()
{
    if (_ppParkinsonSigma != NULL)
    {
	    delete _ppParkinsonSigma;
        _ppParkinsonSigma = NULL;
    }
}
Cephei::QL::Models::Volatility::CParkinsonSigma::!CParkinsonSigma ()
{
    if (_ppParkinsonSigma != NULL)
    {
	    delete _ppParkinsonSigma;
    }
}
QuantLib::ParkinsonSigma& Cephei::QL::Models::Volatility::CParkinsonSigma::GetReference ()
{
    if (_ppParkinsonSigma == NULL) throw gcnew NativeNullException ();
	return **_ppParkinsonSigma;
}
boost::shared_ptr<QuantLib::ParkinsonSigma>& Cephei::QL::Models::Volatility::CParkinsonSigma::GetShared ()
{
    if (_ppParkinsonSigma == NULL) throw gcnew NativeNullException ();
	return *_ppParkinsonSigma;
}
QuantLib::ParkinsonSigma* Cephei::QL::Models::Volatility::CParkinsonSigma::GetPointer ()
{
    if (_ppParkinsonSigma == NULL) throw gcnew NativeNullException ();
	return &**_ppParkinsonSigma;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ParkinsonSigma>& Cephei::QL::Models::Volatility::CParkinsonSigma::GetHandle ()
{
	if (_phParkinsonSigma == NULL)
	{
		_phParkinsonSigma = new Handle<QuantLib::ParkinsonSigma> (*_ppParkinsonSigma);
	}
	return *_phParkinsonSigma;
}
#endif
bool Cephei::QL::Models::Volatility::CParkinsonSigma::HasNative () 
{
	return (_ppParkinsonSigma != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::Volatility::IParkinsonSigma^ Cephei::QL::Models::Volatility::CParkinsonSigma_Factory::Create (Double y)
{
    return gcnew CParkinsonSigma ( y);
}
